package com.study.hospital_3.controller;

import com.study.hospital_3.pojo.Department;
import com.study.hospital_3.service.impl.DepartmentServiceImpl;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import io.swagger.annotations.Api;

import javax.annotation.Resource;

/**
 * (Department)表控制层
 *
 * @author hcl
 * @since 2025-01-19 09:37:04
 */
@RestController
@RequestMapping("department")
@Api(value = "(Department)",tags = "(Department)接口API")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentServiceImpl departmentServiceImpl;

    /**
     * 一次性全部查询
     *
     * @return 查询结果
     */
    @GetMapping("/selectAll")
    public Map<String, Object> selectAll() {
        System.out.println(departmentServiceImpl.selectAll().get("data"));
        return departmentServiceImpl.selectAll();
    }

    /**
     * 分页查询
     *
     * @param department 筛选条件
     * @param page        要查询第几页
     * @param limit       每页显示多少条
     * @return 查询结果
     */
    @GetMapping("/selectByLimit")
    public Map<String, Object> selectByLimit(Department department, @RequestParam int page, @RequestParam int limit) {
        return departmentServiceImpl.selectByLimit(department, page, limit);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectById")
    public Map<String, Object> selectById(@RequestParam Integer id) {
        return departmentServiceImpl.selectById(id);
    }

    /**
     * 新增数据
     *
     * @param department 实体
     * @return 新增结果
     */
    @PostMapping("/insert")
    public Map<String, Object> insert(@RequestBody Department department) {
        return departmentServiceImpl.insert(department);
    }

    /**
     * 编辑数据
     *
     * @param department 实体
     * @return 编辑结果
     */
    @PostMapping("/updateById")
    public Map<String, Object> updateById(@RequestBody Department department) {
        System.out.println("-----------------");
        System.out.println(department.getId());
        System.out.println(department.getDepartmentName());
        return departmentServiceImpl.updateById(department);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteById")
    public Map<String, Object> deleteById(@RequestParam Integer id) {
        return departmentServiceImpl.deleteById(id);
    }

    @GetMapping("/selectAllT")
    public Map<String, Object> selectAllT(){
        return departmentServiceImpl.selectAllT();
    }
}

